import {dataViewTypes} from "@/components/form/type";
import FieldComponentDelegate from "@/components/FormEngine/FieldComponentDelegate";

export default {
    render(context) {
        let view = this.getRenderView(context)
        if (!view) return [];

        return (view.configs || [])
            .map(config => this.renderViewItem(config, context))
            .filter(i => !!i)
    },

    renderViewItem(config, context) {
        if (config.dataViewType === dataViewTypes.field) {
            return FieldComponentDelegate.render(config, context);
        }
    },

    getRenderView({formDefinition, view}) {
        return (formDefinition && formDefinition.views || []).find(v => v.id === view);
    },
}